// T2. Distance from School and Child Development
// T2. Distance from School and Child Development
// T2. Distance from School and Child Development


// PRELIMINARIES

clear
set more off
set scheme s1mono

local controls "i.childage haz male cgmom momeduc momluo hhsize sibs numassets haz_imputed dadabsent dadeduc dadluo missing_data i.schoolid"


// LOAD DATA
	
use "JakielaOzierFernaldKnauer-preschool-data.dta", replace



// REDUCED FORM RESULTS


** a. reduced form ECD index

forvalues i = 3/6 {
	reg ecdindex schdist `controls' if roundage==`i', cluster(respid)
	mat V = r(table)
	local _beta`i' = string(V[1,1],"%04.3f")
	local _se`i' = string(V[2,1],"%04.3f")
	local _pval`i' = string(V[4,1],"%04.3f")
	local _obs`i' = e(N)
}
cap file close fh
file open fh using "out/T2A-rfecd.tex", write replace

file write fh "Distance to school (km) & `_beta3' & `_beta4' & `_beta5' & `_beta6'  \\ [0.8ex] " _newline
file write fh "		    & (`_se3') & (`_se4') & (`_se5') & (`_se6')  \\ [0.8ex] " _newline
file write fh "		    & [`_pval3'] & [`_pval4'] & [`_pval5'] & [`_pval6']  \\ [0.8ex] " _newline

file close fh


** b. reduced form luo receptive vocab

forvalues i = 3/6 {
	reg zluovocab schdist `controls' if roundage==`i', cluster(respid)
	mat V = r(table)
	local _beta`i' = string(V[1,1],"%04.3f")
	local _se`i' = string(V[2,1],"%04.3f")
	local _pval`i' = string(V[4,1],"%04.3f")
	local _obs`i' = e(N)
}
cap file close fh
file open fh using "out/T2B-rfluo.tex", write replace

file write fh "Distance to school (km) & `_beta3' & `_beta4' & `_beta5' & `_beta6'  \\ [0.8ex] " _newline
file write fh "		    & (`_se3') & (`_se4') & (`_se5') & (`_se6')  \\ [0.8ex] " _newline
file write fh "		    & [`_pval3'] & [`_pval4'] & [`_pval5'] & [`_pval6']  \\ [0.8ex] " _newline

file close fh


** c. reduced form english receptive vocab

forvalues i = 3/6 {
	reg zengvocab schdist `controls' if roundage==`i', cluster(respid)
	mat V = r(table)
	local _beta`i' = string(V[1,1],"%04.3f")
	local _se`i' = string(V[2,1],"%04.3f")
	local _pval`i' = string(V[4,1],"%04.3f")
	local _obs`i' = e(N)
}
cap file close fh
file open fh using "out/T2C-rfeng.tex", write replace

file write fh "Distance to school (km) & `_beta3' & `_beta4' & `_beta5' & `_beta6'  \\ [0.8ex] " _newline
file write fh "		    & (`_se3') & (`_se4') & (`_se5') & (`_se6')  \\ [0.8ex] " _newline
file write fh "		    & [`_pval3'] & [`_pval4'] & [`_pval5'] & [`_pval6']  \\ [0.8ex] " _newline

file close fh


** d. reduced form expressive vocab

forvalues i = 3/6 {
	reg zexpvocab schdist `controls' if roundage==`i', cluster(respid)
	mat V = r(table)
	local _beta`i' = string(V[1,1],"%04.3f")
	local _se`i' = string(V[2,1],"%04.3f")
	local _pval`i' = string(V[4,1],"%04.3f")
	local _obs`i' = e(N)
}
cap file close fh
file open fh using "out/T2D-rfexp.tex", write replace

file write fh "Distance to school (km) & `_beta3' & `_beta4' & `_beta5' & `_beta6'  \\ [0.8ex] " _newline
file write fh "		    & (`_se3') & (`_se4') & (`_se5') & (`_se6')  \\ [0.8ex] " _newline
file write fh "		    & [`_pval3'] & [`_pval4'] & [`_pval5'] & [`_pval6']  \\ [0.8ex] " _newline


file close fh


** e. reduced form fine motor

forvalues i = 3/6 {
	reg zmotor schdist `controls' if roundage==`i', cluster(respid)
	mat V = r(table)
	local _beta`i' = string(V[1,1],"%04.3f")
	local _se`i' = string(V[2,1],"%04.3f")
	local _pval`i' = string(V[4,1],"%04.3f")
	local _obs`i' = e(N)
}
cap file close fh
file open fh using "out/T2E-rfmotor.tex", write replace

file write fh "Distance to school (km) & `_beta3' & `_beta4' & `_beta5' & `_beta6'  \\ [0.8ex] " _newline
file write fh "		    & (`_se3') & (`_se4') & (`_se5') & (`_se6')  \\ [0.8ex] " _newline
file write fh "		    & [`_pval3'] & [`_pval4'] & [`_pval5'] & [`_pval6']  \\ [0.8ex] " _newline

file close fh

cap file close fh
file open fh using "out/T2-rfinfo.tex", write replace

file write fh "Obs. & `_obs3' & `_obs4' & `_obs5' & `_obs6'  \\ [0.8ex] " _newline

file close fh
